<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User,
                 com.scalar.forecast.commons.Constants,
                 com.scalar.forecast.commons.SessionKeys"%>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Scalarsoft - ChipTrac </TITLE>
<META NAME="Generator" CONTENT="">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% User user1 = (User) session.getAttribute (SessionKeys.USER_KEY); %>
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<SCRIPT>
var ctrlName = window.opener.fieldLabelName + 'Values';
function showFieldValues()
{
	var fieldName = window.opener.fieldName;
	fieldLabel.innerText = "User Defined Field: " + fieldName;
    var fieldValues =   window.opener[ ctrlName ];
    if ( fieldValues.length == 0 )
    {
        addRow ( 'rowId',"",true );
    }
    else
    {
        for ( i=0; i < fieldValues.length; i++ )
        {
            if ( i == 0 )
            {
                addRow ( 'rowId', fieldValues[i], true );
            }
            else
            {
                addRow ( 'rowId', fieldValues[i] );
            }
        }
    }
}
function closeWindow()
{
	window.close();
}
function onSubmit()
{
   updateFieldValues();
   closeWindow();
}
function updateFieldValues()
{
    form = document.userDefinedFieldValuesForm;
    fieldValues = form [ ctrlName ];
    if ( fieldValues.length == null )
    {
        window.opener.updateFieldValues ( ctrlName, 0, fieldValues.value );
    }
    else
    {
        for ( i=0; i < fieldValues.length ; i++ )
        {
            window.opener.updateFieldValues ( ctrlName, i, fieldValues[i].value );
        }
    }
}
function addRow( rowId, fieldValue, showAddmore )
{
    var txValue = "";
    if ( typeof fieldValue != 'undefined' )
    {
        txValue = fieldValue;
    }
	var row = document.getElementById(rowId);
    var table = row.parentElement;
    var newRow = table.insertRow(row.rowIndex);
    var td = newRow.insertCell();
	td.width = "62";
	td.innerHTML="&nbsp;";
    td = newRow.insertCell();
	td.width="128";
    td.innerHTML = '<input type=text class=txfield size="20"  name="' + ctrlName + '" value="' + txValue + '" maxlength="15"/>';
    td = newRow.insertCell();
    if ( typeof showAddmore != 'undefined' && showAddmore == true )
    {
        td.width="61";
        htmlStr = "<a href=\"javascript:addRow('rowId');\"><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align=center onmouseover=\"window.status='Click here to add row';return true\" title=\"Click here to add row\" onmouseout=\"window.status='';return true\"></a>";
        td.innerHTML = htmlStr;
    }
}


</SCRIPT>

</HEAD>

<BODY onLoad="showFieldValues()">
<form name="userDefinedFieldValuesForm">
<center>
<TABLE border="0">
    <% if ( !user1.isActionAllowed ( Functionality.FORECAST_SETUP,User.USER_ACTION_MODIFY ) ) { %>
    <tr><td colspan=3 align='left'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></td></tr> <% } %>
	<TR>
		<TD colspan="3" bgColor=#993333 width="263" height="16"><FONT class="NArialL" style="color:#ffffff" id="fieldLabel">&nbsp;User Defined Field:</FONT></TD>
	</TR>

	<TR>
		<TD class="NArialL" align="right" width="62"> Values:</TD>
		<TD colspan="2" width="195">&nbsp;</TD>
	</TR>
	<%--<TR>
		<TD width="62">&nbsp;</TD>
		<TD width="128"><input type="text" class="txfield" size="20"></TD>
		<TD width="61"><a href="javascript:addRow('rowId');"><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align=center></a></TD>
	</TR>--%>
	<TR  id="rowId"><TD colspan="3" ></TD></TR>
	<TR>
		<TD width="62">&nbsp;</TD>
		<TD colspan="2" width="195">&nbsp;</TD>
	</TR>
	<TR>
		<TD colspan="6" align="center" width="263">
                    <chiptrack:restrictedLink functionality='<%=Functionality.FORECAST_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:onSubmit();" onmouseover="window.status='Click here to save list values';return true" onmouseout="window.status='';return true">
					    <IMG onmouseover="window.status='Click here to save list values';return true" title="Click here to save list values" onmouseout="window.status='';return true" height=17 src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width=53 border=0>
                    </chiptrack:restrictedLink>&nbsp;&nbsp;&nbsp;&nbsp;
			        <a href="javascript:document.userDefinedFieldValuesForm.reset();"><IMG onmouseover="window.status='Click here to Reset';return true" title="Click here to Reset" onmouseout="window.status='';return true" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border=0 width="53" height="17"></a>&nbsp;&nbsp;&nbsp;&nbsp;
				    <a href="javascript:closeWindow();"><IMG onmouseover="window.status='Click here to Cancel';return true" onmouseout="window.status='';return true" title="Click here to Cancel " src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" border=0 width="53" height="17"></a></TD>
	</TR>
</TABLE>
</center>
</form>
</BODY>
</HTML>